package com.relife.sys.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.relife.common.model.AjaxJson;
import com.relife.common.model.Page;
import com.relife.common.utils.StringUtil;
import com.relife.core.easyui.Easyui;
import com.relife.core.entity.ProcessSetEntity;
import com.relife.core.qbc.QbcQuery;
import com.relife.sys.service.ProcessSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



/**
 * 流程设置表
 * 
 * @author WU
 * @date 2016-05-19 17:17:20
 */
@Controller
@RequestMapping("sys/processSet")
public class ProcessSetController extends BaseController {
	@Autowired
	private ProcessSetService processSetService;

	/**
	 * 
	 * @author WU
	 * @date 2016年5月20日 下午4:55:14
	 * @param req
	 * @return
	 */
	@RequestMapping
	public String processSetList(HttpServletRequest req) {
		return "sys/processSet/processSetList";
	}

	/**
	 * 
	 * @author WU
	 * @date 2016年5月20日 下午4:55:22
	 * @param req
	 * @return
	 */
	@RequestMapping
	public String selectProcessSet(HttpServletRequest req) {
		return "sys/processSet/selectProcessSet";
	}

	/**
	 * 数据列表
	 * 
	 * @author WU
	 * @date 2016-05-19 17:17:20
	 * @param processSet
	 * @param page
	 */
	@RequestMapping
	public void listData(ProcessSetEntity processSet, Page page, HttpServletResponse res) {
		QbcQuery qbc = new QbcQuery(processSet);
		processSetService.getPage(qbc, page);
		Easyui.datagrid(page, res);
	}

	/**
	 * @author WU
	 * @date 2016-05-19 17:17:20
	 * @param processSet
	 * @param req
	 * @return
	 */
	@RequestMapping
	public String processSet(ProcessSetEntity processSet, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(processSet.getId())) {
			processSet = processSetService.get(ProcessSetEntity.class, processSet.getId());
		}
		req.setAttribute("page", processSet);
		return "sys/processSet/processSet";
	}

	/**
	 * 保存
	 * 
	 * @author WU
	 * @date 2016-05-19 17:17:20
	 * @param processSet
	 * @return
	 */
	@ResponseBody
	@RequestMapping
	public AjaxJson save(ProcessSetEntity processSet) {
		AjaxJson j = new AjaxJson();
		try {
			processSetService.saveOrUpdate(processSet);
		} catch (Exception e) {
			j.setException(e);
			e.printStackTrace();
		}
		return j;
	}

	/**
	 * 删除
	 * 
	 * @author WU
	 * @date 2016-05-19 17:17:20
	 * @param processSet
	 * @return
	 */
	@ResponseBody
	@RequestMapping
	public AjaxJson del(ProcessSetEntity processSet) {
		AjaxJson j = new AjaxJson();
		try {
			processSetService.delete(processSet);
		} catch (Exception e) {
			j.setException(e);
			e.printStackTrace();
		}
		return j;
	}
}
